package cn.itcast.service.impl;

import cn.itcast.feign.pojo.PageBean;
import cn.itcast.feign.pojo.User;
import cn.itcast.mapper.UserMapper;
import cn.itcast.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public User getById(Long userId) {
        User user = userMapper.getByUserId(userId);
        return user;
    }

    @Override
    public void delete(Long userId) {
        userMapper.deleteById();
    }

    @Override
    public void insert(User user) {
      userMapper.insert(user);
    }

    @Override
    public void update(User user) {
      userMapper.update(user);
    }

    @Override
    public PageBean page(Integer currentPage, Integer pageSize, String name, String sex) {
        PageHelper.startPage(currentPage,pageSize);
        List<User> userList=userMapper.list(name,sex);
        Page<User> p= (Page<User>) userList;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }
}
